//递归获取ID集
export function getIds(obj) {
    let ids = [];

    // 递归遍历对象  
    function traverse(obj) {
        if (typeof obj === 'object' && obj !== null) {
            if ('id' in obj) { // 检查是否存在id属性  
                ids.push(obj.id);
            }
            for (let key in obj) {
                traverse(obj[key]); // 递归遍历子对象  
            }
        }
    }

    traverse(obj);
    return ids;
}

export function getNestedProperty(obj, keyString) {
    // 将键字符串拆分为键数组  
    const keys = keyString.split('.');

    function traverse(obj, keys, index = 0) {
        if (index >= keys.length || obj === null || obj === undefined) {
            return undefined;
        }

        const key = keys[index];
        const value = obj[key];

        if (index === keys.length - 1) {
            return value;
        }

        return traverse(value, keys, index + 1);
    }

    return traverse(obj, keys);
}